from typing import List
from fastapi import APIRouter, Depends
from app.api.admin.schemas.user import UserInSchema, UserOutSchema, UserSearchSchema
from app.api.admin.service.user import UserService
from app.utils.res import unified_resp
user = APIRouter(prefix="/user")


@user.get("/", tags=["用户中心"], response_model=List[UserOutSchema])
async def list(user_search_data: UserSearchSchema, user_service: UserService = Depends(UserService.instence)):
    '''获取所有'''

    return await user_service.get_list(user_search_data)


@user.post("/", tags=["用户中心"])
async def create(user_in: UserInSchema, user_service: UserService = Depends(UserService.instence)):
    '''新增'''
    return await user_service.create(user_in)


@user.get("/test", tags=["用户中心"])
async def test(user_in: UserInSchema, user_service: UserService = Depends(UserService.instence)):
    '''编辑'''
    await user_service.edit(**user_in.model_dump())
    return {"message": "User edited"}
